package lambdademo;
import java.util.Comparator;
import java.util.PriorityQueue;
//无返回值无参数
@FunctionalInterface
//函数式接口
//只能有一个方法
interface NoParameterNoReturn {
    void test();
}
//无返回值一个参数
@FunctionalInterface
interface OneParameterNoReturn {
    void test(int a);
}
//无返回值多个参数
@FunctionalInterface
interface MoreParameterNoReturn {
    void test(int a,int b);
}
//有返回值无参数
@FunctionalInterface
interface NoParameterReturn {
    int test();
}
//有返回值一个参数
@FunctionalInterface
interface OneParameterReturn {
    int test(int a);
}
//有返回值多参数
@FunctionalInterface
interface MoreParameterReturn {
    int test(int a,int b);
}
public class Test {
    public static void main(String[] args) {
        NoParameterReturn noParameterReturn = ()->{return 0;};
        noParameterReturn.test();
        OneParameterReturn oneParameterReturn = a -> {return a;};
        System.out.println(oneParameterReturn.test(10));
        MoreParameterReturn moreParameterReturn = (a,b)-> a+b;
        System.out.println(moreParameterReturn.test(10, 20));
    }
    public static void main2(String[] args) {
        //无返回值
        NoParameterNoReturn noParameterNoReturn = new NoParameterNoReturn() {
            @Override
            public void test() {
                System.out.println("test");
            }
        };
        noParameterNoReturn.test();
        System.out.println("********");
        NoParameterNoReturn noParameterNoReturn1 = ()-> System.out.println("test");
        noParameterNoReturn1.test();
        System.out.println("********");
        OneParameterNoReturn oneParameterNoReturn = (a)-> System.out.println(a);
        oneParameterNoReturn.test(10);
        System.out.println("***********");
        MoreParameterNoReturn moreParameterNoReturn = (a,b)->{
            System.out.println(a+b);
        };
        moreParameterNoReturn.test(10,20);
        System.out.println("************");
    }
    public static void main1(String[] args) {
        int a = 10;
        //在匿名内部类中和lamba表达式中只能使用常量
        PriorityQueue<Integer> priorityQueue = new PriorityQueue<>(new Comparator<Integer>() {
            @Override
            public int compare(Integer o1, Integer o2) {
                  return o2-o1;
            }
        });
        //lambda表达式
        //代码可读性弱
        PriorityQueue<Integer> priorityQueue1 = new PriorityQueue<>(((o1, o2) -> {return  o2-o1;}));
    }
}
